package gui;

import classes.Servidor;
import classes.Tarefa;
import classes.TarefaAndamento;
import classes.TarefaServidor;
import java.awt.event.KeyEvent;
import controlador.LoginControlador;
import erro.ConexaoException;
import erro.ConsultaException;
import erro.GeralException;
import fachada.Fachada;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.mail.EmailException;
import rn.Email;
import rn.TarefaStatus;

/**
 *
 * @author Roberta
 */
public class TarefaMostrar extends javax.swing.JFrame {

    public static int mat;
    public static int codigo;
    DefaultListModel dlm = new DefaultListModel();
    DefaultListModel dlm2 = new DefaultListModel();
    Tarefa tarefa = new Tarefa();

    /** Creates new form TarefaMostrar */
    public TarefaMostrar() {
        initComponents();
        this.setLocationRelativeTo(null);
        btReiniciar.setVisible(false);
        textDetalhe.setEditable(false);
        textAtividade.setEditable(false);
        textDataInc.setEnabled(false);
        textDataP.setEnabled(false);
        btSalvar.setVisible(false);
        paneBt.setVisible(false);
        listServidor.setVisible(false);
        btReiniciar.setVisible(false);
        buttonGroup1.setSelected(null, false);
        carregartbAndamento();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textDetalhe = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        textAtividade = new javax.swing.JTextField();
        textDataP = new com.toedter.calendar.JDateChooser();
        lbStatus = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        list2 = new javax.swing.JList();
        paneBt = new javax.swing.JPanel();
        btAdd = new javax.swing.JButton();
        btRemove = new javax.swing.JButton();
        btAddAll = new javax.swing.JButton();
        btRemoveAll = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        listServidor = new javax.swing.JList();
        jPanel5 = new javax.swing.JPanel();
        rdAlta = new javax.swing.JRadioButton();
        rdMedia = new javax.swing.JRadioButton();
        rdBaixa = new javax.swing.JRadioButton();
        lbDataI = new javax.swing.JLabel();
        textDataInc = new com.toedter.calendar.JDateChooser();
        jPanel2 = new javax.swing.JPanel();
        btTarefaConc = new javax.swing.JButton();
        btTarefaInic = new javax.swing.JButton();
        btReiniciar = new javax.swing.JButton();
        btAlterar = new javax.swing.JButton();
        btExcluir = new javax.swing.JButton();
        btAndamento = new javax.swing.JButton();
        btEmail = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();
        paneAndamento = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tbAndamento1 = new javax.swing.JTable();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Detalhes da Tarefa");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setText("Atividade:");

        jLabel5.setText("Data de Inclusão:");

        jLabel2.setText("Data inicial:");

        jLabel6.setText("Data Prevista:");

        jLabel8.setText("Status:");

        jLabel4.setText("Detalhamento:");

        textDetalhe.setColumns(20);
        textDetalhe.setFont(new java.awt.Font("Tahoma", 0, 12));
        textDetalhe.setRows(5);
        jScrollPane1.setViewportView(textDetalhe);

        jLabel1.setText("Servidor:");

        textAtividade.setScrollOffset(2);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        list2.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        jScrollPane2.setViewportView(list2);

        btAdd.setText(">");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });

        btRemove.setText("<");
        btRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveActionPerformed(evt);
            }
        });

        btAddAll.setText(">>");
        btAddAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddAllActionPerformed(evt);
            }
        });

        btRemoveAll.setText("<<");
        btRemoveAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveAllActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout paneBtLayout = new javax.swing.GroupLayout(paneBt);
        paneBt.setLayout(paneBtLayout);
        paneBtLayout.setHorizontalGroup(
            paneBtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btAddAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(btRemoveAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(btRemove, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
            .addComponent(btAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
        );
        paneBtLayout.setVerticalGroup(
            paneBtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneBtLayout.createSequentialGroup()
                .addComponent(btAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRemove)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btAddAll)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRemoveAll)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        listServidor.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        jScrollPane5.setViewportView(listServidor);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(paneBt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(paneBt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Prioridade"));

        buttonGroup1.add(rdAlta);
        rdAlta.setText("Alta");

        buttonGroup1.add(rdMedia);
        rdMedia.setText("Média");

        buttonGroup1.add(rdBaixa);
        rdBaixa.setText("Baixa");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rdAlta)
                .addGap(18, 18, 18)
                .addComponent(rdMedia)
                .addGap(18, 18, 18)
                .addComponent(rdBaixa)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rdAlta)
                    .addComponent(rdMedia)
                    .addComponent(rdBaixa))
                .addContainerGap(11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbDataI)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel8)
                                .addGap(10, 10, 10)
                                .addComponent(lbStatus))
                            .addComponent(textAtividade, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(textDataInc, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(textDataP, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(textAtividade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(textDataP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textDataInc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lbDataI)
                    .addComponent(lbStatus)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        btTarefaConc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/fim.png"))); // NOI18N
        btTarefaConc.setText("Concluir");
        btTarefaConc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTarefaConcActionPerformed(evt);
            }
        });
        btTarefaConc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btTarefaConcKeyPressed(evt);
            }
        });

        btTarefaInic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/inicio.png"))); // NOI18N
        btTarefaInic.setText("Iniciar");
        btTarefaInic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTarefaInicActionPerformed(evt);
            }
        });
        btTarefaInic.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btTarefaInicKeyPressed(evt);
            }
        });

        btReiniciar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/copy.png"))); // NOI18N
        btReiniciar.setText("Reiniciar");
        btReiniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btReiniciarActionPerformed(evt);
            }
        });
        btReiniciar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btReiniciarKeyPressed(evt);
            }
        });

        btAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/editar.png"))); // NOI18N
        btAlterar.setText("Alterar");
        btAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarActionPerformed(evt);
            }
        });
        btAlterar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btAlterarKeyPressed(evt);
            }
        });

        btExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/excluir.png"))); // NOI18N
        btExcluir.setText("Excluir");
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });
        btExcluir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btExcluirKeyPressed(evt);
            }
        });

        btAndamento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/andamento.png"))); // NOI18N
        btAndamento.setText("Andamento");
        btAndamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAndamentoActionPerformed(evt);
            }
        });
        btAndamento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btAndamentoKeyPressed(evt);
            }
        });

        btEmail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/email.png"))); // NOI18N
        btEmail.setText("Reenviar e-mail");
        btEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEmailActionPerformed(evt);
            }
        });
        btEmail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btEmailKeyPressed(evt);
            }
        });

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/salvar.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btReiniciar, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btAndamento, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btTarefaInic, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btTarefaConc, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btExcluir, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(btAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addComponent(btSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btAndamento)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btTarefaInic)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btTarefaConc)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btExcluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btEmail)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btReiniciar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btAlterar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btSalvar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        paneAndamento.setBorder(javax.swing.BorderFactory.createTitledBorder("Andamento:"));

        jScrollPane6.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane6.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        tbAndamento1.setAutoCreateRowSorter(true);
        tbAndamento1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cód.", "Data", "Observação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbAndamento1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        tbAndamento1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tbAndamento1.setMaximumSize(new java.awt.Dimension(1350, 0));
        tbAndamento1.setMinimumSize(new java.awt.Dimension(160, 64));
        tbAndamento1.setPreferredSize(new java.awt.Dimension(600, 64));
        tbAndamento1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbAndamento1MouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(tbAndamento1);
        tbAndamento1.getColumnModel().getColumn(0).setPreferredWidth(40);
        tbAndamento1.getColumnModel().getColumn(0).setMaxWidth(50);
        tbAndamento1.getColumnModel().getColumn(1).setMinWidth(90);
        tbAndamento1.getColumnModel().getColumn(1).setPreferredWidth(90);
        tbAndamento1.getColumnModel().getColumn(1).setMaxWidth(90);

        javax.swing.GroupLayout paneAndamentoLayout = new javax.swing.GroupLayout(paneAndamento);
        paneAndamento.setLayout(paneAndamentoLayout);
        paneAndamentoLayout.setHorizontalGroup(
            paneAndamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneAndamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                .addContainerGap())
        );
        paneAndamentoLayout.setVerticalGroup(
            paneAndamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneAndamentoLayout.createSequentialGroup()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(paneAndamento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(paneAndamento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btTarefaInicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTarefaInicActionPerformed
        TarefaDataInicio tdi = new TarefaDataInicio();
        tdi.setLocationRelativeTo(null);
        tdi.setVisible(true);
    }//GEN-LAST:event_btTarefaInicActionPerformed

    private void btTarefaConcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTarefaConcActionPerformed
        TarefaDataConclusao tdf = new TarefaDataConclusao();
        tdf.setLocationRelativeTo(null);
        tdf.setVisible(true);
    }//GEN-LAST:event_btTarefaConcActionPerformed

    private void btAndamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAndamentoActionPerformed
        TarefaAndamentoTela tat = new TarefaAndamentoTela();
        tat.setLocationRelativeTo(null);
        tat.setVisible(true);
    }//GEN-LAST:event_btAndamentoActionPerformed

    private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarActionPerformed
        carregarList();
        textAtividade.setEditable(true);
        textDetalhe.setEditable(true);
        textDataInc.setEnabled(true);
        textDataP.setEnabled(true);
        paneBt.setVisible(true);
        listServidor.setVisible(true);
        btSalvar.setVisible(true);
        buttonGroup1.setSelected(null, true);
    }//GEN-LAST:event_btAlterarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        int selectedOption = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir a tarefa?", "Alerta!", JOptionPane.YES_NO_OPTION);
        if (selectedOption == JOptionPane.YES_OPTION) {
            Tarefa t = new Tarefa();
            TarefaServidor ts = new TarefaServidor();
            TarefaAndamento ta = new TarefaAndamento();
            Fachada f = new Fachada();
            t.setTarefa_id(TarefaMostrar.mat);
            ts.setTarefa_id(t);
            try {
                f.pesquisar(t);
                if (t.getStatus() == 7) {
                    f.deletarAnd(ta);
                    f.deletarTarefa(t, ts);
                    JOptionPane.showMessageDialog(null, "Tarefa excluída definitivamente!");
                    this.dispose();
                } else {
                    t.setStatus(7);//Status de excluídas.   
                    f.alterarStatus(t);
                    JOptionPane.showMessageDialog(null, "Tarefa excluída!");
                    this.dispose();
                }
            } catch (ConexaoException ex) {
                JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
            } catch (ConsultaException ex) {
                JOptionPane.showMessageDialog(null, "Não foi possível excluir a tarefa!\n" + ex);
            }
        } else {
            this.repaint();
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void btReiniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btReiniciarActionPerformed
        TarefaCadastrar tc = new TarefaCadastrar();
        tc.textAtividade.setText(textAtividade.getText());
        tc.textDetalhe.setText(textDetalhe.getText());
        if (rdAlta.isSelected()) {
            tc.rdAlta.setSelected(true);
        } else if (rdMedia.isSelected()) {
            tc.rdMedia.setSelected(true);
        } else if (rdBaixa.isSelected()) {
            tc.rdBaixa.setSelected(true);
        }
        tc.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btReiniciarActionPerformed

    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
    }//GEN-LAST:event_formFocusGained

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        carregarTabela();
        carregartbAndamento();
    }//GEN-LAST:event_formWindowGainedFocus

    private void btEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEmailActionPerformed
        int selectedOption = JOptionPane.showConfirmDialog(null, "Deseja realmente reenviar e-mail?", "Sistema informa:", JOptionPane.YES_NO_OPTION);
        if (selectedOption == JOptionPane.YES_OPTION) {
            reEmail();
        } else {
            this.repaint();
        }
    }//GEN-LAST:event_btEmailActionPerformed

    private void btEmailKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btEmailKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btEmailActionPerformed(null);
        }
    }//GEN-LAST:event_btEmailKeyPressed

    private void btReiniciarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btReiniciarKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btReiniciarActionPerformed(null);
        }
    }//GEN-LAST:event_btReiniciarKeyPressed

    private void btExcluirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btExcluirKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btExcluirActionPerformed(null);
        }
    }//GEN-LAST:event_btExcluirKeyPressed

    private void btAlterarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btAlterarKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btAlterarActionPerformed(null);
        }
    }//GEN-LAST:event_btAlterarKeyPressed

    private void btTarefaConcKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btTarefaConcKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btTarefaConcActionPerformed(null);
        }
    }//GEN-LAST:event_btTarefaConcKeyPressed

    private void btTarefaInicKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btTarefaInicKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btTarefaInicActionPerformed(null);
        }
    }//GEN-LAST:event_btTarefaInicKeyPressed

    private void btAndamentoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btAndamentoKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btAndamentoActionPerformed(null);
        }
    }//GEN-LAST:event_btAndamentoKeyPressed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        Fachada f = new Fachada();
        if (textDataInc.getDate() == null || textDataP.getDate() == null) {
            JOptionPane.showMessageDialog(null, "Digite uma data!");
        }
        try {
            Fachada fachada = new Fachada();
            Servidor s = new Servidor();
            TarefaServidor ts = new TarefaServidor();
            String lc = LoginControlador.login; //Pega o login.
            s.setLogin(lc);
            fachada.pesquisarLogin(s);//Pesquisa o login.
            tarefa.setSolicitante(s);
            tarefa.setAtividade(textAtividade.getText().trim());
            tarefa.setDetalhe(textDetalhe.getText().trim());
            tarefa.setDataPrevista(textDataP.getDate());
            tarefa.setDataInclusão(textDataInc.getDate());
            int prioridade = 0;

            if (rdAlta.isSelected()) {
                prioridade = 3;//Se a prioridade for alta seta o número 3 no banco.
            }
            if (rdMedia.isSelected()) {
                prioridade = 2;//Se a prioridade for alta seta o número 2 no banco.
            }
            if (rdBaixa.isSelected()) {
                prioridade = 1;//Se a prioridade for alta seta o número 1 no banco.
            }
            tarefa.setPrioridade(prioridade);
            tarefa.setStatus(0);//zero é o status de tarefa não iniciada.
            s = new Servidor();
            ArrayList lista = new ArrayList();
            ArrayList<Servidor> listaServidores = fachada.listar(s);
            DefaultListModel modelol = (DefaultListModel) list2.getModel();
            for (int l = 0; l < modelol.getSize(); l++) {
                String servAtual = modelol.getElementAt(l).toString();
                for (Servidor serv : listaServidores) {
                    if (serv.getNome().equals(servAtual)) {
                        lista.add(serv);
                    }
                }
            }
            tarefa.setTarefa_id(TarefaMostrar.mat);
            ts.setTarefa_id(tarefa);
            ts.setServidor(lista);
            f.alterarTarefa(tarefa, ts);
            TarefaStatus.alterarStatus();
            carregarTabela();
            btSalvar.setVisible(false);
        } catch (ConexaoException e) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + e);
        } catch (ConsultaException e) {
            JOptionPane.showMessageDialog(null, "Não foi possível alterar a tarefa!\n" + e);
        } catch (GeralException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
            this.repaint();
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        dlm = (DefaultListModel) list2.getModel();
        if (listServidor.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(null, "Selecione pelo menos um Servidor.");
        } else {
            for (int i = 0; i < listServidor.getSelectedValuesList().size(); i++) {
                dlm.addElement(listServidor.getSelectedValue());
            }
            list2.setModel(dlm);
            int[] selecao = listServidor.getSelectedIndices();
            for (int i = selecao.length; i > 0; i--) {
                int j = listServidor.getSelectedIndex();
                ((DefaultListModel) listServidor.getModel()).remove(j);
            }
        }
    }//GEN-LAST:event_btAddActionPerformed

    private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
        if (list2.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(null, "Selecione pelo menos um Servidor.");
        } else {
            dlm2 = (DefaultListModel) listServidor.getModel();
            for (int i = 0; i < list2.getSelectedValuesList().size(); i++) {
                int j = list2.getSelectedIndex();
                dlm2.addElement(list2.getSelectedValue());
            }
            listServidor.setModel(dlm2);

            int[] selecao = list2.getSelectedIndices();
            for (int i = selecao.length; i > 0; i--) {
                int j = list2.getSelectedIndex();
                ((DefaultListModel) list2.getModel()).remove(j);
            }
        }
    }//GEN-LAST:event_btRemoveActionPerformed

    private void btAddAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddAllActionPerformed
        int indices = listServidor.getModel().getSize() + 1;
        final int[] vetor = new int[indices];
        for (int i = 0; i < indices; i++) {
            vetor[i] = i;
        }
        listServidor.setSelectedIndices(vetor);
        dlm = (DefaultListModel) list2.getModel();
        for (int i = 0; i < listServidor.getSelectedValuesList().size(); i++) {
            dlm.addElement(listServidor.getModel().getElementAt(i));
        }
        list2.setModel(dlm);

        int[] selecao = listServidor.getSelectedIndices();
        for (int i = selecao.length; i > 0; i--) {
            ((DefaultListModel) listServidor.getModel()).remove(0);
        }
    }//GEN-LAST:event_btAddAllActionPerformed

    private void btRemoveAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveAllActionPerformed
        int indices = list2.getModel().getSize() + 1;
        final int[] vetor = new int[indices];
        for (int i = 0; i < indices; i++) {
            vetor[i] = i;
        }
        list2.setSelectedIndices(vetor);
        dlm2 = (DefaultListModel) listServidor.getModel();
        for (int i = 0; i < list2.getSelectedValuesList().size(); i++) {
            dlm2.addElement(list2.getModel().getElementAt(i));
        }
        listServidor.setModel(dlm2);

        int[] selecao = list2.getSelectedIndices();
        for (int i = selecao.length; i > 0; i--) {
            ((DefaultListModel) list2.getModel()).remove(0);
        }
    }//GEN-LAST:event_btRemoveAllActionPerformed

    private void textDetalheKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textDetalheKeyPressed
    }//GEN-LAST:event_textDetalheKeyPressed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    }//GEN-LAST:event_formWindowOpened

    private void tbAndamento1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbAndamento1MouseClicked
        Fachada f = new Fachada();
        if (evt.getClickCount() == 2) {//se o clique for duplo  
            int x = tbAndamento1.getSelectedRow(); //Pega o índice da linha selecionada.                                   
            TarefaMostrar.codigo = (Integer) tbAndamento1.getValueAt(x, 0);
            AndamentoAlterar aa = new AndamentoAlterar();
            if (evt.getButton() == MouseEvent.BUTTON1) {//e o botão for o esquerdo.
                TarefaAndamento ta = new TarefaAndamento();
                ta.setIdAndamento(TarefaMostrar.codigo);
                // aa.carregarTabela();
                aa.setVisible(true);
            }
        }        // TODO add your handling code here:
}//GEN-LAST:event_tbAndamento1MouseClicked
    DefaultTableCellRenderer letras = new DefaultTableCellRenderer() {

        @Override
        public void setValue(Object value) {

            setHorizontalAlignment(JLabel.LEFT);

            super.setValue(value);
        }
    };

    public void reEmail() {
        Fachada f = new Fachada();
        Tarefa t = new Tarefa();
        Servidor s = new Servidor();
        t.setTarefa_id(TarefaMostrar.mat);
        ArrayList<TarefaServidor> listaTs;

        try {
            listaTs = (ArrayList) f.pesquisarTs();
            ArrayList<Servidor> lista = new ArrayList();
            t = f.pesquisar(t);
            ArrayList<Servidor> listaServidores = f.listar(s);

            for (int l = 0; l < listaTs.size(); l++) {
                String servAtual = listaTs.get(l).getNome();
                for (Servidor serv : listaServidores) {
                    if (serv.getNome().equals(servAtual)) {
                        lista.add(serv);
                    }
                }
            }
            String emails = "";
            String nomes = "";
            String separador = "";

            for (int n = 0; n < lista.size(); n++) {
                if (listaTs.size() != 1) {
                    if (n + 1 == lista.size()) {
                        separador = "";
                    } else {
                        separador = ", ";
                    }
                }
                nomes += lista.get(n).getNome() + separador;

                if (lista.get(n).getEmail() == 1) {
                    emails += lista.get(n).getEmailPessoal().toLowerCase().trim() + ",";
                }
                emails += lista.get(n).getEmailProf().toLowerCase().trim() + separador;
            }
            int getPri = tarefa.getPrioridade();
            String setPri = null;
            switch (getPri) {
                case 3:
                    setPri = "Alta";
                    break;
                case 2:
                    setPri = "Média";
                    break;
                case 1:
                    setPri = "Baixa";
                    break;
            }
            String status = "";
            switch (tarefa.getStatus()) {
                case 0:
                    status = "Não iniciada.";
                    break;
                case 1:
                    status = "Não iniciada em 24 horas.";
                    break;
                case 2:
                    status = "Não iniciada em 5 dias (atrasada).";
                    break;
                case 3:
                    status = "Iniciada.";
                    break;
                case 4:
                    status = "Iniciada, em andamento.";
                    break;
                case 5:
                    status = "Atrasada.";
                    break;

            }
            DateFormat formatdata = new SimpleDateFormat("dd/MM/yyyy");
            Date data = tarefa.getDataPrevista();
            String datA = (formatdata.format(data));

            for (int i = 0; i < lista.size(); i++) {
                Email.assunto = "Lembrete da Tarefa: " + tarefa.getAtividade();
                Email.conteudo = "Status: " + status + "\n"
                        + "Deverá ser concluída até: " + datA + "\n" + "Tarefa: " + tarefa.getAtividade()
                        + "." + "\n" + "Prioridade: " + setPri + "." + "\n" + "Detalhamento: " + tarefa.getDetalhe()
                        + "." + "\n" + "Responsáveis: " + nomes + ".";
            }
            Email.destino = emails;
            Email e = new Email();
            e.enviaEmail();
            JOptionPane.showMessageDialog(null, "Enviado com sucesso!");
            textDetalhe.grabFocus();
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados! \n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro na consulta dos dados da Tarefa.\n" + ex);
        } catch (EmailException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }

    public void carregarTabela() {
        textDetalhe.setEditable(false);
        textAtividade.setEditable(false);
        textDataInc.setEnabled(false);
        textDataP.setEnabled(false);
        btSalvar.setVisible(false);
        paneBt.setVisible(false);
        btReiniciar.setVisible(false);
        listServidor.setVisible(false);
        buttonGroup1.setSelected(null, false);
        carregartbAndamento();
        String dataC = "";
        try {
            Fachada f = new Fachada();
            Tarefa t = new Tarefa();
            TarefaServidor ts = new TarefaServidor();
            ArrayList<TarefaServidor> listaTs = (ArrayList) f.pesquisarTs();
            t.setTarefa_id(TarefaMostrar.mat);
            Tarefa lista = f.pesquisar(t);
            DateFormat formatdata = new SimpleDateFormat("dd-MM-yyyy");
            Date dataConc = lista.getDataConclusão();
            if (dataConc != null) {
                dataC = (formatdata.format(dataConc));
            }
            int getstatus = lista.getStatus();
            String setStatus = null;
            switch (getstatus) {
                case 5:
                    setStatus = "Tarefa atrasada";
                    break;
                case 4:
                    setStatus = "Passou 50% do tempo previsto";
                    break;
                case 3:
                    setStatus = "Tarefa iniciada em andamento";
                    break;
                case 2:
                    setStatus = "Tarefa não iniciada atrasada a mais de 5 dias";
                    break;
                case 1:
                    setStatus = "Tarefa não iniciada atrasada";
                    break;
                case 0:
                    setStatus = "Tarefa não iniciada";
                    break;
                case 6:
                    setStatus = "Concluída";
                    break;
                case 7:
                    setStatus = "Excluída";
                    break;
            }
            if ("Concluída".equals(setStatus)) {
                btTarefaConc.setEnabled(false);
                btReiniciar.setVisible(true);
                btAndamento.setEnabled(false);
                btAlterar.setEnabled(false);
                btEmail.setEnabled(false);
                setStatus = "Concluída em: " + dataC;
            }
            if ("Excluída".equals(setStatus)) {
                btTarefaConc.setEnabled(false);
                btReiniciar.setVisible(true);
                btAndamento.setEnabled(false);
                btAlterar.setEnabled(false);
                btTarefaInic.setEnabled(false);
                btEmail.setEnabled(false);
                btExcluir.setEnabled(true);
                setStatus = "Concluída em: " + dataC;
            }
            if (LoginControlador.nivel == 3) {
                btReiniciar.setVisible(false);
            }
            String dataInic = null;
            if (lista.getDataInicial() != null) {
                btTarefaInic.setEnabled(false);
                Date dataIni = lista.getDataInicial();
                dataInic = (formatdata.format(dataIni));
            } else {
                dataInic = ("Não Iniciada.");
                btTarefaConc.setEnabled(false);
                btAndamento.setEnabled(false);
            }
            textAtividade.setText(lista.getAtividade());
            textDetalhe.setText(lista.getDetalhe());
            lbDataI.setText(dataInic);
            textDetalhe.setWrapStyleWord(true);
            textDetalhe.setLineWrap(true);
            textDataInc.setDate(lista.getDataInclusão());
            textDataP.setDate(lista.getDataPrevista());
            switch (lista.getPrioridade()) {
                case 1:
                    rdBaixa.setSelected(true);
                    break;
                case 2:
                    rdMedia.setSelected(true);
                    break;
                case 3:
                    rdAlta.setSelected(true);
                    break;
            }
            lbStatus.setText(setStatus);
            DefaultListModel modeloList = new DefaultListModel();
            for (int i = 0; i < listaTs.size(); i++) {
                ts.setTarefa_id(listaTs.get(i).getTarefa_id());
                int p = ts.getTarefa_id().getTarefa_id();
                if (p == lista.getTarefa_id()) {
                    modeloList.addElement(listaTs.get(i).getNome());
                }
                list2.setModel(modeloList);
            }
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar carregar a tela!\n" + ex);
        }
    }

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TarefaMostrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TarefaMostrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TarefaMostrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TarefaMostrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TarefaMostrar().setVisible(true);
            }
        });
    }

    public final void carregartbAndamento() {
        Fachada f = new Fachada();
        TarefaAndamento ta = new TarefaAndamento();
        Tarefa t = new Tarefa();
        DefaultTableModel modelo = (DefaultTableModel) tbAndamento1.getModel();
        modelo.setNumRows(0);
        t.setTarefa_id(TarefaMostrar.mat);
        ta.setTarefa_id(t);
        ArrayList<TarefaAndamento> lista = new ArrayList<TarefaAndamento>();
        try {
            lista = f.listar();
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar listar os Andamentos desta Tarefa!\n" + ex);
        }
        DateFormat formatdata = new SimpleDateFormat("dd-MM-yyyy");

        for (int i = 0; i < lista.size(); i++) {
            Date data = lista.get(i).getData();
            String dataP = (formatdata.format(data));
            modelo.addRow(new Object[]{lista.get(i).getIdAndamento(), dataP, lista.get(i).getObs()});
        }

        tbAndamento1.setModel(modelo);
    }

    public void carregarList() {
        Fachada f = new Fachada();
        Servidor s = new Servidor();
        int indices = list2.getModel().getSize();
        final int[] vetor = new int[indices];
        for (int i = 0; i < indices; i++) {
            vetor[i] = i;
        }
        list2.setSelectedIndices(vetor);
        DefaultListModel modelo = new DefaultListModel();
        DefaultListModel modelo2 = new DefaultListModel();
        ArrayList<Servidor> lista = new ArrayList<Servidor>();
        ArrayList lista2 = new ArrayList();
        try {
            lista = f.listar(s);
            lista2 = (ArrayList) list2.getSelectedValuesList();
            for (int i = 0; i < lista.size(); i++) {
                modelo.addElement(lista.get(i).getNome());
            }
            for (int i = 0; i < lista2.size(); i++) {
                String atual = (String) lista2.get(i);
                for (Servidor serv : lista) {
                    if (serv.getNome().toLowerCase().trim().equals(atual.toLowerCase().trim())) {
                        modelo2.addElement(serv.getNome());
                        modelo.removeElement(serv.getNome());
                    }
                }
            }
            listServidor.setModel(modelo);
            list2.setModel(modelo2);
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar carregar a lista de Servidores.\n" + ex);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btAddAll;
    public javax.swing.JButton btAlterar;
    public javax.swing.JButton btAndamento;
    public javax.swing.JButton btEmail;
    public javax.swing.JButton btExcluir;
    public javax.swing.JButton btReiniciar;
    private javax.swing.JButton btRemove;
    private javax.swing.JButton btRemoveAll;
    private javax.swing.JButton btSalvar;
    public javax.swing.JButton btTarefaConc;
    public javax.swing.JButton btTarefaInic;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lbDataI;
    private javax.swing.JLabel lbStatus;
    private javax.swing.JList list2;
    private javax.swing.JList listServidor;
    private javax.swing.JPanel paneAndamento;
    private javax.swing.JPanel paneBt;
    private javax.swing.JRadioButton rdAlta;
    private javax.swing.JRadioButton rdBaixa;
    private javax.swing.JRadioButton rdMedia;
    public javax.swing.JTable tbAndamento1;
    private javax.swing.JTextField textAtividade;
    private com.toedter.calendar.JDateChooser textDataInc;
    private com.toedter.calendar.JDateChooser textDataP;
    private javax.swing.JTextArea textDetalhe;
    // End of variables declaration//GEN-END:variables
}
